/*
 * @Description:
 * @Author: 胡涛
 * @Date: 2023-06-06 09:20:37
 * @LastEditors: 胡涛
 * @LastEditTime: 2024-07-17 23:59:03
 */
import { EnterpriseDto, OrganizationDto } from "@/api/organize/types";
import { AttachmentConfigDto } from "@/api/resource/types";
import { RegionDto, RoleDto, SystemUserDto } from "@/api/system/types";
import { IDictionaryItem } from "@/types";
import { defineStore } from "pinia";

/**
 * 公共数据接口
 */
interface IDataState {
  dictionaryItems: Array<IDictionaryItem>;
  roleItems: Array<RoleDto>;
  userItems: Array<SystemUserDto>;
  organizationItems: Array<OrganizationDto>;
  enterpriseItems: Array<OrganizationDto>;
  attachmentConfigItems: Array<AttachmentConfigDto>;
  regionItems: Array<RegionDto>;
}

export const useDataStore = defineStore("data", {
  state: (): IDataState => {
    return {
      dictionaryItems: [],
      roleItems: [],
      userItems: [],
      organizationItems: [],
      enterpriseItems: [],
      attachmentConfigItems: [],
      regionItems: [],
    };
  },
  actions: {
    setAllDictionaryItems(items: Array<IDictionaryItem>) {
      this.dictionaryItems = items;
    },
    setAllRoleItems(items: Array<RoleDto>) {
      this.roleItems = items;
    },
    setAllUserItems(items: Array<SystemUserDto>) {
      this.userItems = items;
    },
    setAllEnterpriseItems(items: Array<EnterpriseDto>) {
      this.enterpriseItems = items;
    },
    setAllOrganizationItems(items: Array<OrganizationDto>) {
      this.organizationItems = items;
    },
    setAllAttachmentConfigItems(items: Array<AttachmentConfigDto>) {
      this.attachmentConfigItems = items;
    },
    setAllRegionItems(items: Array<RegionDto>) {
      this.regionItems = items;
    },
  },
  persist: {
    enabled: true,
    strategies: [{ storage: localStorage, key: "vite-vue-store-data" }],
  },
});
